﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using pooling;

public class ParticleManager : MonoBehaviour
{
    public static ParticleManager instance;

    public GameObject BurstParticlePrefab;
    public GameObject CoinAnimationPrefab;
    public PrizeAnimation PrizeAnimationObject;
    public ParticleSystem BestScoreParticle;

    public Transform ParticleField;
    //public Vector3 PrizeStartPosition;

    private Pooling<BurstParticle> burstParticlePool = new Pooling<BurstParticle>();
    private Pooling<CoinAnimation> coinAnimationPool = new Pooling<CoinAnimation>();

    private void Awake()
    {
        instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        burstParticlePool.createMoreIfNeeded = true;
        burstParticlePool.Initialize(BurstParticlePrefab, ParticleField);

        coinAnimationPool.createMoreIfNeeded = true;
        coinAnimationPool.Initialize(CoinAnimationPrefab, ParticleField);
        
    }

    public void SpawnBurstParticle(Vector3 position, Color color)
    {
        burstParticlePool.Collect().InitParticle(position, color);
    }

    public void PlayHammerParticle(Vector3 position)
    {
        burstParticlePool.Collect().InitParticle(position, Color.grey);
    }

    public void PlayCoinAnimation(Vector3 position)
    {
        AudioController.Play("Coin");
        var _coin = coinAnimationPool.Collect();
        _coin.transform.GetComponent<CoinAnima>().SetShow();
        _coin.InitAnimation(position);
    }

    public void PlayPrizeAanimation()
    {
        AudioController.Play("Prize");
        PrizeAnimationObject.PlayPrizeAnimation();
    }

    public void PlayNewBestScoreParticle()
    {
        BestScoreParticle.Play();
        AudioController.Play("Achievement");
    }
}
